package sk.mucha.tracking;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.Request;
import org.apache.wicket.Session;
import org.apache.wicket.protocol.http.WebSession;

import sk.mucha.tracking.classes.User;

public class MySession extends WebSession {

	private static final long serialVersionUID = 1L;
	private String userEmail;
	private List<User> users;
	
	public MySession(Request request) {
		super(request);
		users = ((WicketApplication)getApplication()).getUsers();
	}

	public boolean login(String userEmail, String password) {
		boolean bool = false;
		for(User u:users) {
			if (u.getUserEmail().equalsIgnoreCase(userEmail)) {
				if (u.getUserPasswd().equals(password)) {
					this.userEmail = userEmail;
					bool = true;
				}
			}
		}
		return bool;
	}
	
	public String getUserEmail() {
		return userEmail;
	}
	
	public static MySession get() {
	      return (MySession)Session.get();
	}
}
